#pragma once

#include "Device.h"
#include "NeroCore\NMath.h"

namespace Graphics
{
	class Texture;
	class Buffer;
}

namespace Graphics
{
class ParticleSystem
{
private:
	struct ParticleType
	{
		float positionX, positionY, positionZ;
		float red, green, blue;
		float velocity;
		bool active;
	};

	struct VertexType
	{
		D3DXVECTOR3 position;
		D3DXVECTOR4 color;
		D3DXVECTOR2 texture;
	};

public:
	ParticleSystem(void);
	virtual ~ParticleSystem(void);
	bool Initialize();
	void Deinitialize();
	bool Update(float gameTime);
	void Render();

	Texture* GetTexture();
	int GetIndexCount();
	int GetCurrentNumberOfParticles(){return mCurrentParticleCount;}

private:
	bool InitializeParticleSystem();
	void DeinitializeParticleSystem();
	bool InitializeBuffers();
	void DeinitializeBuffers();
	void EmitParticles(float);
	void UpdateParticles(float gameTime);
	void KillParticles();
	bool UpdateBuffers();
	void RenderBuffers();

private:
	NVector3 mParticleDeviation;
	float mParticleVelocity;
	float mParticleVelocityVariation;

	float mParticleSize;
	float mParticlesPerSecond;
	int mMaxParticles;

	int mCurrentParticleCount;
	float mAccumulatedTime;

	Texture* mTexture;

	ParticleType* mParticleList;

	int mVertexCount;
	int mIndexCount;
	VertexType* mVertices;
	Buffer* mVertexBuffer;
	Buffer* mIndexBuffer;
};
}